//
//  ALTools.h
//  TestAfn2
//
//  Created by xujingjing on 16/7/8.
//  Copyright © 2016年 xujingjing. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface ALTools : NSObject

/**
 *  获取宽度与高度
 */
#define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width
#define SCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height

#define  GET_X(element) ( element.frame.origin.x +element.frame.size.width)
#define  GET_Y(element) ( element.frame.origin.y +element.frame.size.height)

#define  GET_ONE_X(element) ( element.frame.origin.x)
#define  GET_ONE_Y(element) ( element.frame.origin.y)


#define   STORY [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]


+(NSData *)dataWithImage:(UIImage *)image;  // return data,压缩图片为data  imagedata 待压缩图片
+(UIImage*)imageWithImage:(UIImage*)image;  // return image,压缩图片



//按比例大小裁剪图片
+ (UIImage *)cutImage:(UIImage*)image TargetIV:(UIImageView *)targetIV;
+ (UIImage *)cutImage:(UIImage*)image TargetSize:(CGSize)targetSize;

#define height(h) (IMAGE_RATE_HEIGHT*h)

#define width(w) (IMAGE_RATE_WIDTH*w)

#define  IMAGE_RATE_WIDTH (SCREEN_WIDTH/375.0)  //750
#define  IMAGE_RATE_HEIGHT (SCREEN_HEIGHT/667.0)  //1334



//字体,颜色

#define FONT(R) [UIFont systemFontOfSize:R]

#define ColorWithRGB(R,G,B) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1.0]
#define ColorWithOne(R) [UIColor colorWithRed:R/255.0 green:R/255.0 blue:R/255.0 alpha:1.0]

#define ColorWithRandom [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0] //随机颜色
#define  Color_clear [UIColor clearColor]


//log
#ifdef DEBUG
#define ALLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define LRLog(...)
#endif



#define WeakSelf(type)  __weak typeof(type) weak##type = type;  //弱引用
#define StrongSelf(type)  __strong typeof(type) type = weak##type;  //强引用


//设置圆角 边宽 边框颜色
#define ViewRadiusBorderWidth(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]


//注册不带object的通知
#define ADD_NIL_OBSERVER(action,actionName) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(action) name:actionName object:nil]
////注册带object 的通知
#define POST_NOTIFICATION(_name,_object)  [[NSNotificationCenter defaultCenter] postNotificationName:_name object:_object];
//注册不带object 的通知
#define POST_NOTIFICATION_NIL(_name,_object)  [[NSNotificationCenter defaultCenter] postNotificationName:_name object:nil];
//移除通知
#define REMOVE_OBSERVER [[NSNotificationCenter defaultCenter] removeObserver:self]


#define DefaultIMG [UIImage imageNamed:@"defaultImage"]  //默认本地图片

//常用数值设置
#define MAX_PHONE_LEGNTH  11
#define MAX_PSW_LENGTH  18
#define MAX_VALICODE_LENGTH 6
#define SPACE 10


#define PATH_OF_DOCUMENT    [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

+ (NSInteger)OSVersion;
+(void)ttAlert:(NSString *)message;  //UIAlertView提示框

//缓存，文件操作
+ (NSString*)getCacheDirectory;
+ (BOOL)fileExistsAtPath:(NSString*)_path;
+ (BOOL)deleteFileAtPath:(NSString*)_path;
+ (NSString*)getPathByFileName:(NSString *)_fileName ofType:(NSString *)_type;
+ (NSString*)getPathByFileName:(NSString *)_fileName;


//获取字符串长度
+(float)getStringWidth:(NSString *)text;
//获取字符串长度
+(float)getStringWidth:(NSString *)text andSize:(CGSize)size andFont:(NSInteger)font;
//获取字符串高度
+(float)getStringHeight:(NSString *)text andSize:(CGSize)size andFont:(NSInteger)font;
//计算一个数组中文字要变成按钮的高度
+(NSInteger)caculateRowHeight:(NSArray *)array andFont:(NSInteger)font;



+(BOOL)checkTel:(NSString *)str; //验证是否是手机号
+ (NSString*)makePhoneNumChangeState:(NSString *)phone;  //电话号码中间为**** 例：183****5092








@end
